#!/bin/sh

TMPFILE=/tmp/mysql-sync-temp.`date +%Y%m%d%H%M%S%N`.sql
NS1=10.10.99.92
NS2=10.10.99.70
NS3=10.10.1.91
RTN=0
# dump records
mysqldump --opt -u root --password=dns_r00t dns> $TMPFILE
if [ "${?}" = 0 ]; then
	echo "Dumping Records: Finished."
else
	echo "Dumping Records: Error. (${?})"
	rm $TMPFILE
	exit 1
fi
#update ns1
mysql --host=$NS1 --connect_timeout=3 -u named --password=n4m3d dns< $TMPFILE
if [ "${?}" = 0 ]; then
	echo "Exporting Records to NS1: Finished."
else
        echo "Exporting Records to NS1: Error. (${?})"
	RTN=1
fi
#update ns2
mysql --host=$NS2 --connect_timeout=3 -u named --password=n4m3d dns< $TMPFILE
if [ "${?}" = 0 ]; then
        echo "Exporting Records to NS2: Finished."      
else
        echo "Exporting Records to NS2: Error. (${?})" 
	RTN=1
fi 
#update ns3
mysql --host=$NS3 --connect_timeout=3 -u named --password=n4m3d dns< $TMPFILE
if [ "${?}" = 0 ]; then
        echo "Exporting Records to NS3: Finished."      
else
        echo "Exporting Records to NS3: Error. (${?})" 
	RTN=1
fi 

rm $TMPFILE
echo "done."
exit $RTN
